package com.hy.controller;

import com.hy.admin.pojo.Lideshow;
import com.hy.admin.pojo.vo.LideshowVo;
import com.hy.service.LideshowService;
import com.hy.util.common.Result;
import com.hy.util.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 陌寒    Lenovo
 * @date 2025/3/6上午9:13
 * @description 类描述
 */
@RestController
@RequestMapping("/lideshow")
public class LideshowController {
    @Autowired
    private LideshowService lideshowService;

    /**
     * 分页查询
     * @param lideshowVo
     * @return
     */
    @PostMapping("/getLideshow")
    public Result getLideshow(@RequestBody LideshowVo lideshowVo){
        return lideshowService.getLideshow(lideshowVo);
    }

    /**
     * 添加轮播图
     * @param lideshow
     * @return
     */
    @PostMapping("/addLideshow")
    public Result addLideshow(@RequestBody Lideshow lideshow){
        return lideshowService.addLideshow(lideshow);
    }

    /**
     * 上传图片
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/updatefile")
    public Result<String> fileUploadService(@RequestParam("file") MultipartFile file) throws Exception {
        String fileUrl=lideshowService.updatefile(file);
        return Result.build(fileUrl , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 删除轮播图
     * @param lideshow
     * @return
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestBody Lideshow lideshow){
        return lideshowService.delete(lideshow);
    }

}
